package cn.lili.modules.goods.entity.dto;

import cn.hutool.core.util.StrUtil;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.goods.entity.dos.GoodsDownRecord;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@ApiModel("商品下架记录dto类")
public class GoodsDownRecordDTO extends PageVO {

    @ApiModelProperty(value = "供应商ID")
    private String supplierId;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    @ApiModelProperty("查询类型: 0,所有违规下架记录  1,本月违规下架记录")
    private Integer queryType;

    public LambdaQueryWrapper<GoodsDownRecord> toQueryWarpper() {
        LambdaQueryWrapper<GoodsDownRecord> query = new LambdaQueryWrapper<>();
        query.eq(StrUtil.isNotEmpty(supplierId), GoodsDownRecord::getStoreId, supplierId);
        if (startTime != null && endTime != null) {
            query.ge(GoodsDownRecord::getCreateTime, startTime);
            query.lt(GoodsDownRecord::getCreateTime, endTime);
        }
        query.eq(GoodsDownRecord::getScene, SceneEnums.SUPPLIER.name());
        query.orderByDesc(GoodsDownRecord::getCreateTime).orderByDesc(GoodsDownRecord::getId);
        return query;
    }

}